// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_PUR_PO_ITEM
// * CreateDate    : 2014-02-18 18:04:11
// * Creater       : CodeSmith
// * LastChangeDate: 2014-02-18 18:04:11
// * LastChanger   : 2014-02-18 18:04:11
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Pur
{
/// <summary>
    /// PurPoItem
    /// </summary>
    public partial class PurPoItemBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objPurPoItemEntity">Entity</param>
        /// <returns>Entity</returns>
        public static PurPoItemEntity GetPurPoItem(PurPoItemEntity objPurPoItemEntity)
        {
            return DataAccess.SelectSingle<PurPoItemEntity>(objPurPoItemEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objPurPoItemEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertPurPoItem(PurPoItemEntity objPurPoItemEntity)
        {
            return DataAccess.Insert(objPurPoItemEntity);
        }

        public static bool InsertPurPoItem(List<PurPoItemEntity> objPurPoItemEntityList)
        {
            return DataAccess.Insert(objPurPoItemEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objPurPoItemEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdatePurPoItem(PurPoItemEntity objPurPoItemEntity)
        {
            return DataAccess.Update(objPurPoItemEntity);
        }

        public static bool UpdatePurPoItem(List<PurPoItemEntity> objPurPoItemEntityList)
        {
            return DataAccess.Update<PurPoItemEntity>(objPurPoItemEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objPurPoItemEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeletePurPoItem(PurPoItemEntity objPurPoItemEntity)
        {
            return DataAccess.Delete(objPurPoItemEntity);
        }

        public static bool DeletePurPoItem(List<PurPoItemEntity> objPurPoItemEntityList)
        {
            return DataAccess.Delete<PurPoItemEntity>(objPurPoItemEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetPurPoItemAll()
        {
            return DataAccess.SelectAllDataSet<PurPoItemEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<PurPoItemEntity> GetPurPoItemAllList()
        {
            return DataAccess.SelectAll<PurPoItemEntity>();
        }
        #endregion

        public static List<PurPoItemEntity> GetPoItemAllListByPoNo(string poNo)
        {
            if (string.IsNullOrEmpty(poNo))
                return null;
            return DataAccess.Select<PurPoItemEntity>(new PurPoItemEntity { PoNo = poNo });

        }

        public static PurPoItemEntity GetPoItemByInvIo(string poId, string materialId)
        {
            string sql = @"select item.* from PUR_PO po
left join PUR_PO_ITEM item on po.PO_NO=item.PO_NO
where po.ID='{0}' and item.MATERIAL_ID='{1}'";
            sql = string.Format(sql, poId, materialId);
            List<PurPoItemEntity> poItems = DataAccess.Select<PurPoItemEntity>(sql);
            if (poItems == null || poItems.Count == 0)
            {
                return null;
            }
            else
            {
                return poItems[0];
            }
        }


	}
	
	
}	

